Public Class Moneda
#Region "Numeros_Letras"
    Public Shared Function NumeroLetras(ByVal value As Double) As String
        Dim strValue As String = String.Empty
        value = Math.Abs(value)        
        Select Case value
            Case 0
                strValue = "CERO"
            Case 1
                strValue = "UN"
            Case 2
                strValue = "DOS"
            Case 3
                strValue = "TRES"
            Case 4
                strValue = "CUATRO"
            Case 5
                strValue = "CINCO"
            Case 6
                strValue = "SEIS"
            Case 7
                strValue = "SIETE"
            Case 8
                strValue = "OCHO"
            Case 9
                strValue = "NUEVE"
            Case 10
                strValue = "DIEZ"
            Case 11
                strValue = "ONCE"
            Case 12
                strValue = "DOCE"
            Case 13
                strValue = "TRECE"
            Case 14
                strValue = "CATORCE"
            Case 15
                strValue = "QUINCE"
            Case Is < 20
                strValue = "DIECI" & NumeroLetras(value - 10)
            Case 20
                strValue = "VEINTE"
            Case Is < 30
                strValue = "VEINTI" & NumeroLetras(value - 20)
            Case 30
                strValue = "TREINTA"
            Case 40
                strValue = "CUARENTA"
            Case 50
                strValue = "CINCUENTA"
            Case 60
                strValue = "SESENTA"
            Case 70
                strValue = "SETENTA"
            Case 80
                strValue = "OCHENTA"
            Case 90
                strValue = "NOVENTA"
            Case Is < 100
                strValue = NumeroLetras(CInt(value \ 10) * 10) & " Y " & NumeroLetras(value Mod 10)
            Case 100
                strValue = "CIEN"
            Case Is < 200
                strValue = "CIENTO " & NumeroLetras(value - 100)
            Case 200, 300, 400, 600, 800
                strValue = NumeroLetras(CInt(value \ 100)) & "CIENTOS"
            Case 500
                strValue = "QUINIENTOS"
            Case 700
                strValue = "SETECIENTOS"
            Case 900
                strValue = "NOVECIENTOS"
            Case Is < 1000
                strValue = NumeroLetras(CInt(value \ 100) * 100) & " " & NumeroLetras(value Mod 100)
            Case 1000
                strValue = "MIL"
            Case Is < 2000
                strValue = "MIL " & NumeroLetras(value Mod 1000)
            Case Is < 1000000
                strValue = NumeroLetras(Int(value \ 1000)) & " MIL"
                If value Mod 1000 Then
                    strValue = strValue & " " & NumeroLetras(value Mod 1000)
                End If
            Case 1000000
                strValue = "UN MILLON"
            Case Is < 2000000
                strValue = "UN MILLON " & NumeroLetras(value Mod 1000000)
            Case Is < 1000000000000.0#
                strValue = NumeroLetras(CInt(value / 1000000)) & " MILLONES "
                If (value - Int(value / 1000000) * 1000000) Then
                    strValue = strValue & " " & NumeroLetras(value - Int(value / 1000000) * 1000000)
                End If
            Case 1000000000000.0#
                strValue = "UN BILLON"
            Case Is < 2000000000000.0#
                strValue = "UN BILLON " & NumeroLetras(value - CInt(value / 1000000000000.0#) * 1000000000000.0#)
            Case Else
                strValue = NumeroLetras(Int(value / 1000000000000.0#)) & " BILLONES"
                If (value - Int(value / 1000000000000.0#) * 1000000000000.0#) Then
                    strValue = strValue & " " & NumeroLetras(value - Int(value / 1000000000000.0#) * 1000000000000.0#)
                End If
        End Select
        Return strValue
    End Function
    Public Shared Function MonedaSoles(ByVal value As Double, Optional ByVal MonedaSol As Boolean = False) As String

        Dim strValue As String = String.Empty

        Dim dblNumero As Double = 0
        Dim intEntero As Integer = 0
        Dim intDecimales As Integer = 0
        Dim strDecimales As String = ""
        Dim strMoneda As String = " Nuevos Soles "
        Dim strNumeroMoneda As String = "(S/. 0.00)"
        Dim strNumeroLetra As String = ""
        Dim strUN As String = "UN "

        dblNumero = Val(value)
        intEntero = Microsoft.VisualBasic.Int(dblNumero)
        intDecimales = CInt((dblNumero - intEntero) * 100)
        strDecimales = intDecimales.ToString("00") & "/100"
        strNumeroLetra = NumeroLetras(intEntero).ToLower

        If MonedaSol = True Then
            strNumeroMoneda = "S/. " & dblNumero.ToString("#,###,###.00")
        Else
            strNumeroMoneda = "(S/. " & dblNumero.ToString("#,###,###.00") & ")"
        End If

        If intEntero.ToString.Length = 4 And Left(intEntero.ToString, 1) = "1" Then
            strUN = "Un "
        Else
            strUN = ""
        End If

        If MonedaSol = True Then
            strMoneda = Left(strMoneda, strMoneda.Length - 1)
            strValue = strNumeroMoneda & " (" & strUN & strNumeroLetra & " y " & strDecimales & strMoneda & ")"
        Else
            strValue = strUN & strNumeroLetra & " y " & strDecimales & strMoneda & strNumeroMoneda
        End If


        Return strValue

    End Function
#End Region
End Class
